package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.Legalperson;
import com.example.entity.ZPerson;
import com.example.mapper.LegalpersonMapper;
import com.example.service.ILegalpersonService;
import com.example.util.Code;
import com.example.util.Result;
import com.example.util.page;
import com.example.util.page3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyhxzy
 * @since 2023-11-03
 */
@RestController
    @RequestMapping("/s/legalperson")

public class LegalpersonController {
    @Autowired
    private ILegalpersonService legalpersonService;
    @Autowired
    private OccController controller;

    //根据id查询个人全部信息
    @RequestMapping("/findAll/{id}")
    public Result findById(@PathVariable Integer id){
        Legalperson all = legalpersonService.findAll(id);
        if (all!=null){
            return new Result(Code.GET_OK, all, "查询成功");
        }else {
            return new Result(Code.GET_ERR,"查询失败");
        }
    }
    //企业分页查询
    @RequestMapping("/findpage")
    public Result findByPara(@RequestBody page3 legalperson) {
        Page<Map> byParams = legalpersonService.findByParams(legalperson);
        if (byParams != null) {
            return new Result(Code.GET_OK, byParams, "查询成功");
        } else {
            return new Result(Code.GET_ERR, "查询失败");
        }
    }



    @PostMapping("/add")
    public Result Add(@RequestBody ZPerson person){
        System.out.println(person);

        int add = legalpersonService.add(person);
        return new Result(Code.SAVE_OK,add,"添加成功");
    }
    @PostMapping("/addzidcard")
    public Result addIdzCard(@RequestBody Legalperson legalperson){
        int i = legalpersonService.addzIdCard(legalperson);
        return new Result(Code.GET_OK,i,"成功");
    }
    @PostMapping("/addfidcard")
    public Result addIdfCard(@RequestBody Legalperson legalperson){
        int i = legalpersonService.addfIdCard(legalperson);
        return new Result(Code.GET_OK,i,"成功");
    }
    @GetMapping("/addZid/{zid}")
    public Result addZid(@PathVariable Integer zid){
        int i = legalpersonService.addZid(zid);
        return new Result(Code.GET_OK,"成功");
    }

}
